<template>
  <div class='container'>
    <el-card class="box-card">
      <!-- 头部 -->
       <div class="header">
         <!-- 左搜索 -->
         <div class="left">
           <div class="z">关键字</div> <el-input  v-model="obj.keyword"> </el-input>
         </div>
         <!-- 右按钮 -->
         <div class="right">
           <el-button @click="obj.keyword=''">清除</el-button>
           <el-button type="primary" @click="search">搜索</el-button>
         </div>
       </div>
       <!-- 文字提示 -->
      <el-tooltip class="item" effect="dark" content="Right Top 提示文字" placement="right-start">
        <span class="el-icon-info">&nbsp;&nbsp;数据一共{{total}}条</span>
      </el-tooltip>
      <!-- 表格 -->
      <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column prop="id" label="编号"  width="200"></el-table-column>
      <el-table-column prop="questionType" label="题型"  width="180">
          <template #default='{row}'>
          <div>{{row.questionType | questionTypeFilter(questionType)}}</div>

        </template>
      </el-table-column>
      <el-table-column prop="questionIDs" label="题目编号"  width="200">

        <template #default='{row}'>
           <div v-for='(item,index) in row.questionIDs' :key='index' ><a href="" @click.prevent="check(item)">{{ item.number}}</a></div>
           <!-- <div v-for="item in  scope" :key="item.id">{{item.number}}</div> -->

        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="录入时间"  width="180"></el-table-column>
      <el-table-column prop="totalSeconds" label="答题时间(s)"  width="180"></el-table-column>
      <el-table-column prop="accuracyRate" label="正确率(%)"  width="180"></el-table-column>
      <el-table-column prop="userName" label="录入人"  width="180"></el-table-column>
      <el-table-column prop="date" label="操作"  width="150">
         <template #default='{row}'>

        <el-button class="btn" type="danger" icon="el-icon-delete" circle @click="del(row)"></el-button>
         </template>
      </el-table-column>

    </el-table>

   <div class="pagination">
       <el-pagination
       background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="obj.page"
      :page-sizes="[20, 30, 50, 100]"
      :page-size="obj.pagesize"
      layout="  prev, pager, next, sizes,jumper"
      :total="total"
      >
    </el-pagination>
   </div>
    </el-card>
    <!-- 题目预览组件 -->
    <questions-preview  v-if='flag' :flag.sync='flag' :data='data'></questions-preview>
  </div>
</template>

<script>
// import { randoms } from '../../api/hmmm/questions'
import { randoms, removeRandoms } from '@/api/hmmm/questions'
import { questionType } from '@/api/hmmm/constants'
export default {
  name: 'Questions',
  data () {
    return {
      total: 0,
      data: {},
      tableData: [],
      questionType,
      flag: false,
      obj: {
        page: 1,
        pagesize: 20,
        keyword: ''
      }
    }
  },

  created () {
    this.getRandomsList()
  },
  methods: {

    // 获取数据
    async getRandomsList () {
      const { data } = await randoms(this.obj)
      this.tableData = data.items
      this.total = data.counts
    },
    // 删除
    async del (data) {
      await removeRandoms(data)
      this.getRandomsList()
    },
    handleSizeChange (val) {
      this.obj.pagesize = val
      this.getRandomsList()
    },
    handleCurrentChange (val) {
      this.obj.page = val
      this.getRandomsList()
    },
    // 搜索
    search () {
      this.getRandomsList()
    },
    // 展示弹框
    check (row) {
      this.flag = true
      this.data = row
    }
  }
}
</script>

<style scoped lang='scss'>
a{
  color: rgb(0, 153, 255);
}
  .header{
    display: flex;
    justify-content: space-between;
    .left{
       display: flex;
       justify-content: space-between;
      margin-left: 10px;
      width: 300px;
      .z{
        width: 100px;
        padding-top: 10px;
        padding-left: 5px;

      }
    }
  }
  .item{
    margin-top: 10px;
    padding-left: 10px;
    background: #ccc;
    height: 30px;
    width: 100%;
    line-height: 30px;
  }
  .btn{
    color: red;
    background-color: #fff;
  }
  .pagination{
    float: right;
  }
</style>
